<template>
    <div id="OrdersTitle">
        <v-details :inputConfig="inputConfig" :detailData="inputData" :rules="rules" @pop="setData"
                   ref="input"></v-details>
    </div>
</template>

<script>
    import details from 'commons/Detail'
    import baseMixin from "@/mixins/BaseMixin";

    export default {
        props: {
            inputData: {
                type: Object,
            }
        },
        mixins: [baseMixin],
        name: "OrdersTitle",
        data() {
            return {
                addflag: false,
                rules: {
                    period_code: [
                        {required: true, trigger: 'blur'},
                    ],
                    period_desc: [
                        {required: true, trigger: 'blur'},
                    ],
                    period_qual: [
                        {required: true, trigger: 'blur'},
                    ],
                    period_qty: [
                        {required: true, trigger: 'blur'},
                    ]
                },
            }
        },
        computed: {
            inputConfig() {
                return [
                    [
                        {
                            type: "input",
                            label: "期段",
                            props: "period_code",
                            disabled: this.addflag
                        },
                        {
                            type: "input",
                            label: this.$t('common.desc'),
                            props: "period_desc"
                        },
                        {
                            type: "select",
                            label: "限定符",
                            props: "period_qual",
                            options: this.getOptions("codelkup/PERQUAL")
                        },
                        {
                            type: "input",
                            label: "期段数量",
                            props: "period_qty",
                        }
                    ],
                    [
                        {
                            type: "input",
                            label: "分隔天数",
                            props: "split_days",
                        },
                        {
                            type: "date",
                            label: "自日期",
                            props: "from_date",
                        },
                        {
                            type: "date",
                            label: "至日期",
                            props: "to_date",
                        }
                    ]
                ]
            }
        },
        methods: {
            setData(data, id, close, listId) {
                if (id == '0') {
                    this.inputData.from_measure_uom = data.uom_code;
                    this.inputData.from_name = data.uom_desc;
                } else if (id == '2') {
                    this.inputData.to_measure_uom = data.uom_code;
                    this.inputData.to_name = data.uom_desc;
                }
                close(false);
            }
        },
        mounted() {
            if (Object.keys(this.$store.state.skip).length !== 0) {
                let data = this.$store.state.skip;
                if (!data.newFlag) {
                    this.addflag = true;
                }
            } else if (!this.$store.state.newFlag) {
                this.addflag = true;
            } else {
                this.addflag = false;
            }
        },
        watch: {},
        components: {
            'v-details': details
        }
    }
</script>

<style scoped>

</style>
